package com.jiangyao.component;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class EmailComponent {
    private final static String NOTICE_SUBJECT_EMAIL_TEMPLATE="应聘{jobName}-{userName}";

    /**
     * 通知邮件模板-（可能很多通知模板）
     */
    private final static String NOTICE_SENDRESUME_EMAIL_TEMPLATE = "【匠要】用户{userName}向{group}投递了{jobName}岗位简历，请及时通知其查看处理";

    private final static String FROM_EMAIL="fl@cuubd.com";
    @Autowired
    private JavaMailSender mailSender;

    public void send(String to, String group,String userName,String jobName){

        String content=NOTICE_SENDRESUME_EMAIL_TEMPLATE.replace("{userName}",userName).replace("{group}",group).replace("{jobName}",jobName);
        String subject=NOTICE_SUBJECT_EMAIL_TEMPLATE.replace("{jobName}", jobName).replace("{userName}", userName);
        sendSimpleEmail(to,subject,content);
    }
    /**
     * 简单文本邮件
     * @param to 收件人
     * @param subject 主题
     * @param content 内容
     */
    public void sendSimpleEmail(String to,String subject,String content){

        //创建SimpleMailMessage对象
        SimpleMailMessage message=new SimpleMailMessage();


        //邮件发送人
        message.setFrom(FROM_EMAIL);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        mailSender.send(message);

    }

}
